<?php
    include("mysql.php");
    $startframe = 0;
    $endframe = 0;
    $clients = 0;
    $frameseach = 0;
    $framesleft = 0;    
    
    $startframe = $_POST["startframe"];
    $endframe = $_POST["endframe"];
    $clients = $_POST["clients"];
    
    Mysql::openConnection();
    $con = Mysql::getConnection();
    Mysql::clearAllData();
    
    $frameseach = ($endframe - $startframe) / $clients;
    $framesleft = (($endframe - $startframe) % $clients);
    
    $lastendframe = 0;
    
    for ($i = 0; $i < $clients; $i++) {
        $startf = ($frameseach * $i) + 1;
        $endf = ($frameseach * $i) + $frameseach;
        if ($endframe - $endf < $frameseach) {
            $endf = $endframe;
        }
        $sql2 = "INSERT INTO job (startframe, endframe)
                VALUES
                ('$startf', '$endf');";
        // echo $sql2 . "<br>";
        if (!mysql_query($sql2,$con))  {
            die('Error: ' . mysql_error());
        }
        $lastendframe = $endf;
    }
    
    Mysql::closeConnection();
    
    header("Location: index.html");
?>